package com.iplatform.iplatformuser.function.resource.service.impl;

import com.iplatform.module.privilege.mate.ResInfoBean;
import com.iplatform.iplatformuser.function.resource.dao.ResourceMapper;
import com.iplatform.iplatformuser.function.resource.service.inter.IResurceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
* Title: ResourceServiceImpl
 * Description:资源信息
 * @author yb
 *
 */
@Service
public class ResourceServiceImpl implements IResurceService{

	@Autowired
	private ResourceMapper mapper;

	@Override
	public List<ResInfoBean> queryResInfo(Map<String, String> formMap) {
		return mapper.queryResInfo(formMap);
	}

	@Override
	public List<ResInfoBean> queryResBySpec(Map<String, String> formMap) {
		return mapper.queryResBySpec(formMap);
	}

	@Override
	public List<ResInfoBean> queryResByOrg(Map<String, String> formMap) {
		return mapper.queryResByOrg(formMap);
	}

	@Transactional
	public Integer insertOrUpdateResOrg(Map<String, String> formMap) {
		return mapper.insertOrUpdateResOrg(formMap);
	}

	@Transactional
	public Integer insertOrUpdateResSpec(Map<String, String> formMap) {
		return mapper.insertOrUpdateResSpec(formMap);
	}

	@Override
	public List<ResInfoBean> findResByGroupId(String groupId) {
		return mapper.findResByGroupId(groupId);
	}

	@Transactional
	public Integer deleteByType(Map<String, String> formMap) {
		return mapper.deleteByType(formMap);
	}

	@Transactional
	public Integer insertOrUpdateResMenu(Map<String, String> formMap) {
		return mapper.insertOrUpdateResMenu(formMap);
	}

	@Override
	public List<ResInfoBean> queryResByMenu(Map<String, String> formMap) {
		return mapper.queryResByMenu(formMap);
	}

	@Transactional
	public Integer insertOrUpdateResTarget(Map<String, String> formMap) {
		return mapper.insertOrUpdateResTarget(formMap);
	}

	@Override
	public List<Map<String, String>> queryResNameAndCode() {
		return mapper.queryResNameAndCode();
	}

	@Override
	public Integer deleteByResIdAndType(Map<String, String> formMap) {
		return mapper.deleteByResIdAndType(formMap);
	}

	@Override
	public void insertOrUpdateResMenuById(Map<String, String> formMap) {
		List<ResInfoBean> list = mapper.queryRes(formMap);
		List<Map<String,Object>> menuList = mapper.queryMenu(formMap);
		for (Map<String,Object> map : menuList) {
			formMap.put("resId", map.get("resId").toString());
			formMap.put("parent", map.get("parentId").toString());
			formMap.put("resName", map.get("resName").toString());
			formMap.put("resCode", map.get("resCode").toString());
			formMap.put("resOrder", map.get("resOrder").toString());
			formMap.put("isDeleted", map.get("isDeleted").toString());
		}
		if(list != null && list.size() != 0) {
			mapper.updateResMenu(formMap);
		} else {
			mapper.insertResMenu(formMap);
		}
	}

	@Override
	public List<ResInfoBean> queryResByOrgForMySql(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.queryResByOrgForMySql(formMap);
	}

	@Override
	public List<ResInfoBean> queryResBySpecForMySql(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.queryResBySpecForMySql(formMap);
	}

	@Override
	public List<ResInfoBean> queryResByMenuForMySql(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.queryResByMenuForMySql(formMap);
	}

	@Override
	public List<ResInfoBean> queryResByManagerOrgForMySql(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.queryResByManagerOrgForMySql(formMap);
	}

	@Override
	public List<ResInfoBean> queryResByManagerOrg(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.queryResByManagerOrg(formMap);
	}

	@Override
	public Integer insertOrUpdateResManagerOrg(Map<String, String> formMap) {
		// TODO Auto-generated method stub
		return mapper.insertOrUpdateResManagerOrg(formMap);
	}

}
